delegation: do not always generate first argument#156798
Conversation
303d29a to
c400cb5
Compare
| struct F(S); | ||
| // In glob delegations silently remove first arg if no params or generate default | ||
| // first arg (`arg0`) if it is a static function. | ||
| reuse impl Trait for F { self.0 } |
There was a problem hiding this comment.
Desugaring:
impl Trait for F {
#[attr = Inline(Hint)]
fn value(self: _) -> _ { self.0.value() }
#[attr = Inline(Hint)]
fn r#ref(self: _) -> _ { self.0.r#ref() }
#[attr = Inline(Hint)]
fn mut_ref(self: _) -> _ { self.0.mut_ref() }
#[attr = Inline(Hint)]
fn static_empty() -> _ { Trait::static_empty() }
#[attr = Inline(Hint)]
fn static_one_param(arg0: _) -> _ { Trait::static_one_param(arg0) }
}First arg transformation is not generated even if a static function has first param.
| struct F2(S); | ||
| impl F2 { | ||
| // In list delegations silently remove first arg if it is not a method. | ||
| reuse <S as Trait>::{value, r#ref, mut_ref, static_empty, static_one_param} { self.0 } |
There was a problem hiding this comment.
Desugaring:
#[attr = Inline(Hint)]
fn value(self: _) -> _ { <S as Trait>::value(self.0) }
#[attr = Inline(Hint)]
fn r#ref(self: _) -> _ { <S as Trait>::r#ref(self.0) }
#[attr = Inline(Hint)]
fn mut_ref(self: _) -> _ { <S as Trait>::mut_ref(self.0) }
#[attr = Inline(Hint)]
fn static_empty() -> _ { <S as Trait>::static_empty() }
#[attr = Inline(Hint)]
fn static_one_param(arg0: _) -> _ { <S as Trait>::static_one_param(arg0) }First arg transformation is not generated even if a static function has first param.
| reuse to_reuse::one_param { self + 1 } | ||
|
|
||
| // In list delegations silently remove first arg if there are no params. | ||
| reuse to_reuse::{empty as empty1, one_param as one_param1} { self + 1 } |
There was a problem hiding this comment.
Desugaring:
// In list delegations silently remove first arg if there are no params.
#[attr = Inline(Hint)]
fn empty1() -> _ { to_reuse::empty() }
#[attr = Inline(Hint)]
fn one_param1(arg0: _) -> _ { to_reuse::one_param(self + 1) }We generated first arg transformation as it is a free function.
There was a problem hiding this comment.
After updates we emit error if target expression is specified for list free functions delegations with parameterless functions.
c400cb5 to
3983a7b
Compare
|
|
||
| struct F3(S); | ||
| impl Trait for F3 { | ||
| reuse trait_to_reuse::{value, r#ref, mut_ref, static_empty, static_one_param} { self.0 } |
There was a problem hiding this comment.
Desugaring:
#[attr = Inline(Hint)]
fn value(self: _) -> _ { trait_to_reuse::value(self.0) }
#[attr = Inline(Hint)]
fn r#ref(self: _) -> _ { trait_to_reuse::r#ref(self.0) }
#[attr = Inline(Hint)]
fn mut_ref(self: _) -> _ { trait_to_reuse::mut_ref(self.0) }
#[attr = Inline(Hint)]
fn static_empty() -> _ { trait_to_reuse::static_empty() }
#[attr = Inline(Hint)]
fn static_one_param(arg0: _)
-> _ { trait_to_reuse::static_one_param(arg0) }
//~^ ERROR: mismatched types
//~| ERROR: mismatched typesself resolves to F3.
|
|
||
| struct F4(S); | ||
| impl F4 { | ||
| reuse trait_to_reuse::{value, r#ref, mut_ref, static_empty, static_one_param} { self.0 } |
There was a problem hiding this comment.
Desugaring:
#[attr = Inline(Hint)]
fn value<impl Trait>(arg0: _) -> _ { trait_to_reuse::value(self.0) }
#[attr = Inline(Hint)]
fn r#ref<impl Trait>(arg0: _) -> _ { trait_to_reuse::r#ref(self.0) }
#[attr = Inline(Hint)]
fn mut_ref<impl Trait>(arg0: _) -> _ { trait_to_reuse::mut_ref(self.0) }
#[attr = Inline(Hint)]
fn static_empty() -> _ { trait_to_reuse::static_empty() }
#[attr = Inline(Hint)]
fn static_one_param(arg0: _)
-> _ { trait_to_reuse::static_one_param(self.0) }self resolves to first argument, as it is a plain impl and sig_id resolves to free functions not to a trait method in contrast to case with F3. We generated block for static_one_param as it is a free function, in F3 it is an associated function so we generate arg0.
There was a problem hiding this comment.
After updates we emit error if target expression is specified for list free functions delegations with parameterless functions.
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
|
I think the solution for the dead code problem here brings much worse problems than the initial problem itself. If the target expression is unused, we can generate something like instead of messing with the definition hierarchy. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
Ah, the question is what |
Although leaving e.g. |
|
I just realized that removing code here is a future compatibility hazard. reuse {foo} { std::something_unstable() };If |
|
Also, removing or not removing the target expression depending on whether the delegation is a part of the list or not is probably not a good language design. // now do two different things.
reuse foo;
reuse {foo};I think we'll eventually need to remove the target expression either always, or always for associated functions. |
This comment has been minimized.
This comment has been minimized.
fee11df to
31e3588
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
|
@bors r+ |
…-first-arg, r=petrochenkov delegation: do not always generate first argument This PR supports not generating delegation's "dead code" - situation when there is no parameters in a source function or we expanded a reuse of a static function without self, in this case we do not have to generate delegation's block even if the user has explicitly specified it. We generate block: - If there is a single delegation and source function has first param, otherwise error is emitted, - If there is a glob delegation we generate block if the source function has first param and it is method or free function. Fixes rust-lang#154427. Part of rust-lang#118212. r? @petrochenkov
…uwer Rollup of 8 pull requests Successful merges: - #157467 (stdarch subtree update) - #156798 (delegation: do not always generate first argument) - #157450 (mark `Encode`, `Decode`, `Mark` impls as `#[inline]`) - #157190 (Silence recursive RUSTC_LOG_FORMAT_JSON messages) - #157447 (Move cross crate tests into the appropriate folder) - #157470 (Avoid ICE when emitting TargetMachine config errors) - #157474 (Forbid optimize(none) with inline(always) or inline.) - #157475 (Add a smoke test for the optimize attribute.)
…-first-arg, r=petrochenkov delegation: do not always generate first argument This PR supports not generating delegation's "dead code" - situation when there is no parameters in a source function or we expanded a reuse of a static function without self, in this case we do not have to generate delegation's block even if the user has explicitly specified it. We generate block: - If there is a single delegation and source function has first param, otherwise error is emitted, - If there is a glob delegation we generate block if the source function has first param and it is method or free function. Fixes rust-lang#154427. Part of rust-lang#118212. r? @petrochenkov
…-first-arg, r=petrochenkov delegation: do not always generate first argument This PR supports not generating delegation's "dead code" - situation when there is no parameters in a source function or we expanded a reuse of a static function without self, in this case we do not have to generate delegation's block even if the user has explicitly specified it. We generate block: - If there is a single delegation and source function has first param, otherwise error is emitted, - If there is a glob delegation we generate block if the source function has first param and it is method or free function. Fixes rust-lang#154427. Part of rust-lang#118212. r? @petrochenkov
…uwer Rollup of 12 pull requests Successful merges: - #157467 (stdarch subtree update) - #155453 (apply Cortex-A53 errata 843419 mitigation to the AArch64 Linux targets) - #156798 (delegation: do not always generate first argument) - #157016 (add `extern "tail"` calling convention) - #157450 (mark `Encode`, `Decode`, `Mark` impls as `#[inline]`) - #148183 (rustdoc: Test & document `test_harness` code block attribute) - #157190 (Silence recursive RUSTC_LOG_FORMAT_JSON messages) - #157470 (Avoid ICE when emitting TargetMachine config errors) - #157474 (Forbid optimize(none) with inline(always) or inline.) - #157475 (Add a smoke test for the optimize attribute.) - #157479 (Warn when `#[macro_use]` or `#[macro_escape]` is used on the crate root) - #157486 (Remove unused attributes from issue-29485.rs.) Failed merges: - #157485 (Rename `errors.rs` file to `diagnostics.rs`)
…-first-arg, r=petrochenkov delegation: do not always generate first argument This PR supports not generating delegation's "dead code" - situation when there is no parameters in a source function or we expanded a reuse of a static function without self, in this case we do not have to generate delegation's block even if the user has explicitly specified it. We generate block: - If there is a single delegation and source function has first param, otherwise error is emitted, - If there is a glob delegation we generate block if the source function has first param and it is method or free function. Fixes rust-lang#154427. Part of rust-lang#118212. r? @petrochenkov
Rollup of 12 pull requests Successful merges: - #155453 (apply Cortex-A53 errata 843419 mitigation to the AArch64 Linux targets) - #156798 (delegation: do not always generate first argument) - #157438 (rustdoc: don't link doc(hidden) associated type projections) - #157450 (mark `Encode`, `Decode`, `Mark` impls as `#[inline]`) - #148183 (rustdoc: Test & document `test_harness` code block attribute) - #157190 (Silence recursive RUSTC_LOG_FORMAT_JSON messages) - #157396 (Add @aapoalas to libs review rotation) - #157470 (Avoid ICE when emitting TargetMachine config errors) - #157474 (Forbid optimize(none) with inline(always) or inline.) - #157475 (Add a smoke test for the optimize attribute.) - #157479 (Warn when `#[macro_use]` or `#[macro_escape]` is used on the crate root) - #157486 (Remove unused attributes from issue-29485.rs.) Failed merges: - #157485 (Rename `errors.rs` file to `diagnostics.rs`)
Rollup of 12 pull requests Successful merges: - #157467 (stdarch subtree update) - #155453 (apply Cortex-A53 errata 843419 mitigation to the AArch64 Linux targets) - #156798 (delegation: do not always generate first argument) - #157438 (rustdoc: don't link doc(hidden) associated type projections) - #157450 (mark `Encode`, `Decode`, `Mark` impls as `#[inline]`) - #157190 (Silence recursive RUSTC_LOG_FORMAT_JSON messages) - #157396 (Add @aapoalas to libs review rotation) - #157470 (Avoid ICE when emitting TargetMachine config errors) - #157474 (Forbid optimize(none) with inline(always) or inline.) - #157475 (Add a smoke test for the optimize attribute.) - #157479 (Warn when `#[macro_use]` or `#[macro_escape]` is used on the crate root) - #157486 (Remove unused attributes from issue-29485.rs.) Failed merges: - #157485 (Rename `errors.rs` file to `diagnostics.rs`)
…-first-arg, r=petrochenkov delegation: do not always generate first argument This PR supports not generating delegation's "dead code" - situation when there is no parameters in a source function or we expanded a reuse of a static function without self, in this case we do not have to generate delegation's block even if the user has explicitly specified it. We generate block: - If there is a single delegation and source function has first param, otherwise error is emitted, - If there is a glob delegation we generate block if the source function has first param and it is method or free function. Fixes rust-lang#154427. Part of rust-lang#118212. r? @petrochenkov
Rollup merge of #156798 - aerooneqq:delegation-dont-generate-first-arg, r=petrochenkov delegation: do not always generate first argument This PR supports not generating delegation's "dead code" - situation when there is no parameters in a source function or we expanded a reuse of a static function without self, in this case we do not have to generate delegation's block even if the user has explicitly specified it. We generate block: - If there is a single delegation and source function has first param, otherwise error is emitted, - If there is a glob delegation we generate block if the source function has first param and it is method or free function. Fixes #154427. Part of #118212. r? @petrochenkov
View all comments
This PR supports not generating delegation's "dead code" - situation when there is no parameters in a source function or we expanded a reuse of a static function without self, in this case we do not have to generate delegation's block even if the user has explicitly specified it.
We generate block:
Fixes #154427. Part of #118212.
r? @petrochenkov